package com.hksj.jetlinks.model;

import lombok.Data;

import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

@Data
public class SimpleUserToken implements Serializable {

    private String userId;

    private String token;

    private Long lastRequestTime;

    private Long signInTime;

    private Object state;

    private String type;

    private Long maxInactiveInterval;

    private String userType;

    public static SimpleUserToken of(Map<String,Object> map){
        SimpleUserToken simpleUserToken = new SimpleUserToken();
        simpleUserToken.setUserId(map.getOrDefault("userId","").toString());
        simpleUserToken.setToken(map.getOrDefault("token","").toString());
        simpleUserToken.setLastRequestTime(Objects.isNull(map.get("lastRequestTime")) ? 0L : (Long) map.get("lastRequestTime"));
        simpleUserToken.setSignInTime(Objects.isNull(map.get("signInTime")) ? 0L : (Long) map.get("signInTime"));
        simpleUserToken.setState(map.get("state"));
        simpleUserToken.setType(map.getOrDefault("type","").toString());
        simpleUserToken.setMaxInactiveInterval(Objects.isNull(map.get("maxInactiveInterval")) ? 0L : (Long) map.get("maxInactiveInterval"));
        return simpleUserToken;
    }
}
